/*
 *  AbstractRenderer.cpp
 *  GLRender
 *
 *  Created by Patrick zulian on 5/18/10.
 *  Copyright 2010 University  of Lugano. All rights reserved.
 *
 */

#include "AbstractRenderer.h"

void 
AbstractRenderer::renderMesh(const char * path){
	ObjReader reader;
	Mesh * mesh = reader.readFile(path);
	std::vector< Face > faces = mesh->getFaces();
	
	glBegin(GL_TRIANGLES);
	for (unsigned int i = 0; i < faces.size(); ++i){
		Face f = faces[i];
		std::vector< FacePoint > facePoints = f.getFacePoints();
		
		for ( unsigned int j = 0; j < facePoints.size(); ++j){
			assert( j < 3 );
			FacePoint p = facePoints[j];
			
			if(p.getNormal()!= Mesh::NO_INDEX){
				Point3d norm = mesh->getNormal(p.getNormal());
				glNormal3d(norm.x(), norm.y(), norm.z());
			}
			
			if(p.getTexture()!= Mesh::NO_INDEX){
				Point2d texture= mesh->getTexture(p.getTexture());
				glTexCoord2d(texture.x(), texture.y());
			}
			
			Point3d vertex= mesh->getVertex(p.getVertex());
			glVertex3d(vertex.x(),vertex.y(),vertex.z());
		}
	}
	glEnd();
	
	
	delete(mesh);
}